package com.atguigu.srb.core.controller.admin;


import com.atguigu.srb.base.result.ResponseVo;
import com.atguigu.srb.core.pojo.entity.UserLoginRecord;
import com.atguigu.srb.core.service.UserLoginRecordService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 用户登录记录表 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2024-10-11
 */

@RestController
@RequestMapping("/admin/core/userLoginRecord")
public class AdminUserLoginRecordController {

    @Resource
    UserLoginRecordService userLoginRecordService;

    @ApiOperation("查询会员最近10条登录日志")
    @GetMapping("user/{userId}")
    public ResponseVo list(@PathVariable("userId")Long userId){
        List<UserLoginRecord> userLoginRecordList = userLoginRecordService.list(Wrappers.lambdaQuery(UserLoginRecord.class)
                .eq(UserLoginRecord::getUserId, userId)
                .orderByDesc(UserLoginRecord::getCreateTime)
                .last("limit 10"));

        return ResponseVo.ok().data("items",userLoginRecordList);
    }
}

